<template>
    <div>
      <form action="" @submit.prevent="on_submit">

        用户名:<input type="text" v-model="username">
        <br>
        密码:<input type="password" v-model="password">
        <br>
        确认密码：<input type="password" v-model="password2">
        <br>
        图片<input type="file" id="img">
        <input type="submit" value="注册">
      </form>
    </div>
</template>

<script>
  import axios from 'axios'
    export default {
      name: "Register",
      data:function () {
        return{
          username:'',
          password:'',
          password2:'',
        }
      },
      methods:{
        on_submit(){
          let form_data = new FormData()
          form_data.append('username',this.username)
          form_data.append('password',this.password)
          form_data.append('password2',this.password2)

          form_data.append('file',document.getElementById('img').files[0])


          axios({
            method:'post',
            url:'http://127.0.0.1:8000/register/',
            data:form_data
          }).then(res=>{
            let code=res['data']['code']
            console.log(res)
            if (code==res){
              alert('数据不完整')
            }
            else if (code==res){
              alert('账号重复')
            }
            else {
              this.$router.push({'name':'Login'})
              // alert('注册成功')
            }
          })
        }
      }
    }
</script>

<style scoped>

</style>
